package com.ruoyi.mes.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.mes.domain.ProBomMaterial;
import com.ruoyi.mes.service.IProBomMaterialService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * BOM物料联系Controller
 * 
 * @author ruoyi
 * @date 2024-05-21
 */
@RestController
@RequestMapping("/mes/BomMaterial")
public class ProBomMaterialController extends BaseController
{
    @Autowired
    private IProBomMaterialService proBomMaterialService;

    /**
     * 查询BOM物料联系列表
     */
    @PreAuthorize("@ss.hasPermi('mes:BomMaterial:list')")
    @GetMapping("/list")
    public TableDataInfo list(ProBomMaterial proBomMaterial)
    {
        startPage();
        List<ProBomMaterial> list = proBomMaterialService.selectProBomMaterialList(proBomMaterial);
        return getDataTable(list);
    }

    /**
     * 导出BOM物料联系列表
     */
    @PreAuthorize("@ss.hasPermi('mes:BomMaterial:export')")
    @Log(title = "BOM物料联系", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ProBomMaterial proBomMaterial)
    {
        List<ProBomMaterial> list = proBomMaterialService.selectProBomMaterialList(proBomMaterial);
        ExcelUtil<ProBomMaterial> util = new ExcelUtil<ProBomMaterial>(ProBomMaterial.class);
        util.exportExcel(response, list, "BOM物料联系数据");
    }

    /**
     * 获取BOM物料联系详细信息
     */
    @PreAuthorize("@ss.hasPermi('mes:BomMaterial:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(proBomMaterialService.selectProBomMaterialById(id));
    }

    /**
     * 新增BOM物料联系
     */
    @PreAuthorize("@ss.hasPermi('mes:BomMaterial:add')")
    @Log(title = "BOM物料联系", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ProBomMaterial proBomMaterial)
    {
        return toAjax(proBomMaterialService.insertProBomMaterial(proBomMaterial));
    }

    /**
     * 修改BOM物料联系
     */
    @PreAuthorize("@ss.hasPermi('mes:BomMaterial:edit')")
    @Log(title = "BOM物料联系", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ProBomMaterial proBomMaterial)
    {
        return toAjax(proBomMaterialService.updateProBomMaterial(proBomMaterial));
    }

    /**
     * 删除BOM物料联系
     */
    @PreAuthorize("@ss.hasPermi('mes:BomMaterial:remove')")
    @Log(title = "BOM物料联系", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(proBomMaterialService.deleteProBomMaterialByIds(ids));
    }

}
